var pageI18NArray = ['-', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'];

var backOnEsc = true;

var isInverse = false;
var isDictee = false;
var hasTempo = false;
var tempo = 0;

var hasOnlyOneExercice = false;
var hasOnlyOneBatterie = false;
var hasOnlyOneSerie = false;

var selectedWords, selectedWordsArray, selectedBatterie, selectedSerie, selectedSerieIdx, maxWordPerPage, startTime;

/**
 * initialization
 */
$().ready(function(){
	$(document).keyup(function(e) {
		if (backOnEsc && e.keyCode == 27) {    // esc
			if ($('body').hasClass('popupDisplayed')) {
				// close popup on Esc
				triggerPopup();
			}else{
				// else : go back
				back();
			}
		}
		else if (backOnEsc && e.keyCode == 222) {    // ²
			displayMainMenu();
		}
		else if (e.keyCode > 96 && e.keyCode < 106) {    // short keys
			$('.container:not(.hidden) .shortKey' + (e.keyCode - 96) + ' a').trigger('click');
		}
		else if (e.keyCode > 48 && e.keyCode < 58) {    // short keys
			$('.container:not(.hidden) .shortKey' + (e.keyCode - 48) + ' a').trigger('click');
		}
	});
});

/**
 * Hide all containers
 */
function hideContainers() {
	backOnEsc = true;
	$('.container').addClass('hidden');
}

/**
 * Display container
 */
function showContainer(container) {
    //$('.container:visible').fadeOut(250, 'swing' , function(){});
	var currentBodyClasses = $('body').attr('class');
	$('.' + container).removeClass('hidden');
	$('body').attr('class', currentBodyClasses.replace(/\s?[^\s]*Displayed/, ''));
	$('body').addClass(container + 'Displayed');
}

/**
 * Build the path used by a question
 */
function buildPathForQuestion(batterie_id, question_id) {
	return publicDirectory + '/batteries/' + batterie_id + '/' + question_id + '/';
}

/*
 * Options 
 */

/**
 * changeCharSize
 */
function changeCharSize() {
	$('.lsbm').removeClass('size_0');
	$('.lsbm').removeClass('size_1');
	$('.lsbm').removeClass('size_2');
	$('.lsbm').addClass('size_' + $('#charSize').val());
}

/**
 * Return to the main menu
 */
function displayMainMenu() {
	if (typeof(mainPageLoaded) == 'undefined' || !mainPageLoaded) {
		window.location = mainPagePath;
	}else{
		hideContainers();
		showContainer('menuContainer');
	}
}

/**
 * Log out
 */
function logout() {
	$.ajax({
		type: 'GET',
		url: serverPath + '/auth/logout/',
		success: function(data) {
			window.location = indexPagePath;
		},
		error: function(data) {
			displayPopup("Erreur lors de la déconnexion");
			window.location = indexPagePath;
		},
		dataType: 'json'
	});
	return false;
}


/**
 * Analytics
 */

/* ¤ONLINE */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36775833-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
/* ¤ONLINEEND */
